package com.eos.control.action.customer;

import java.util.List;

import com.eos.business.service.SysProductBusinessService;
import com.eos.common.tool.ConstantTool;
import com.eos.common.tool.ObjectUtils;
import com.eos.control.action.base.AbstractBaseAction;
import com.eos.orm.mybatis.model.SysProduct;
import com.eos.orm.mybatis.model.SysUser;
import com.hf.utils.StringUtil;

public class SaveProductTypeAction extends AbstractBaseAction {
	private static final long serialVersionUID = 3259498695423713537L;
	private String productName;
	private String productDesc;
	
	public void setProductName(String productName) {
		this.productName = productName;
	}

	public void setProductDesc(String productDesc) {
		this.productDesc = productDesc;
	}

	@Override
	public String execute() {
		try {
			if(StringUtil.isEmpty(productName)){
				statusCode = "300";
				message = "保存失败, 请输入品名!";
			}else{
				SysProductBusinessService spbs = new SysProductBusinessService();
				SysProduct product = new SysProduct();
				product.setDealFlag(ConstantTool.DEAL_FALG_OK);
				product.setStatus(ConstantTool.STATUS_OK);
				product.setProductName(productName);
				List<SysProduct> pList = spbs.getSysProductExample(product);
				if(null != pList && pList.size() > 0){
					statusCode = "300";
					message = "保存失败, 输入的品名已经存在!";
				}else{
					SysUser user = (SysUser)getSession().getAttribute("SysUser");
					int userId = user.getId();
					String strTime = ObjectUtils.formatDate(null, "yyyy-MM-dd HH:mm:ss");
					product.setInsertTime(strTime);
					product.setInsertUserId(userId+"");
					product.setModifyTime(strTime);
					product.setProductDesc(productDesc);
					product.setUpdateUserId(userId+"");
					String exeStatus = spbs.saveSysProduct(product);
					if("SUCCESS".equals(exeStatus)){
						statusCode = "200";
						message = "保存品名信息成功!";
					}else{
						statusCode = "300";
						message = "系统繁忙, 保存品名信息失败!";
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			statusCode = "300";
			message = "系统异常, 保存品名信息失败!";
		}
		return SUCCESS;
	}
}
